#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=410;
struct node
{
	int al,h,c;
	bool friend operator <(node a,node b)
	{
		return a.al<b.al;
	}
}a[maxn];
bool f[40001];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i].h,&a[i].al,&a[i].c);
	sort(a+1,a+n+1);
	memset(f,0,sizeof(f));
	f[0]=1;
	for(int i=1;i<=n;i++)
		for(int j=a[i].al;j>=0;j--)
			for(int k=0;k<=a[i].c&&k*a[i].h<=j;k++)
				if(f[j-k*a[i].h]){f[j]=true;break;}
	int ans;
	for(int i=a[n].al;i>=0;i--)
		if(f[i]){ans=i;break;}
	printf("%d\n",ans);
	return 0;
}

